package chapt07.bitmaps;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.awt.GLCanvas;
import javax.swing.JFrame;

import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

 public class BitmapsSwingGLCanvas
 {
 	static
	{
		// setting this true causes window events not to get sent on Linux if
		// you run from inside Eclipse
		GLProfile.initSingleton(false);
	}
	
	public static void main(String[] args)
	{
		GLProfile glprofile = GLProfile.getDefault();
		GLCapabilities glcapabilities = new GLCapabilities(glprofile);
		final GLCanvas glcanvas = new GLCanvas(glcapabilities);
		
		glcanvas.addGLEventListener(new GLEventListener() {
			@Override
			public void reshape(GLAutoDrawable glautodrawable, int x, int y, int w, int h)
			{
				Bitmaps.setup(glautodrawable.getGL().getGL2(), w, h);
			}
			
			@Override
			public void init(GLAutoDrawable glautodrawable)
			{
			
			}
			
			@Override
			public void dispose(GLAutoDrawable glautodrawable)
			{
			
			}
			
			@Override
			public void display(GLAutoDrawable glautodrawable)
			{
				int w = glautodrawable.getWidth();
				int h = glautodrawable.getHeight();
				Bitmaps.render(glautodrawable.getGL().getGL2(), w, h);
			}
		});
		
		final JFrame jframe = new JFrame("OpenGL Bitmaps");
		jframe.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent windowevent)
			{
				jframe.dispose();
				System.exit(0);
			}
		});
		
		jframe.getContentPane().add(glcanvas, BorderLayout.CENTER);
		jframe.setSize(530, 555);
		jframe.setVisible(true);
	}
}